package cn.demomaster.quickui_sample.ui.fragment.component;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.demomaster.quickcompat.widget.button.QuickToggleButton;

import java.util.LinkedHashMap;
import java.util.List;

import cn.demomaster.quickrouter.fragment.QuickFragment;
import cn.demomaster.quickrouter.lifecycle.LifecycleRecorder;
import cn.demomaster.quickrouter.lifecycle.LifecycleTimelineView;
import cn.demomaster.quickrouter.lifecycle.LifecycleView;
import cn.demomaster.quickui.annotation.ActivityPager;
import cn.demomaster.quickui.annotation.ResType;
import cn.demomaster.quickui_sample.R;


/**
 * 时域图
 * Squirrel桓
 * 2018/8/25
 */

@ActivityPager(name = "页面周期监听", preViewClass = TextView.class, resType = ResType.Resource)
//,iconRes = R.drawable.ic_page_cycle)
public class PageCycleFragment extends QuickFragment {

    @NonNull
    @Override
    public View onGenerateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View mView = inflater.inflate(R.layout.fragment_layout_page_cycle, null);
        return mView;
    }

    QuickToggleButton toggle_enable;

    public void initView(View rootView) {
        toggle_enable = rootView.findViewById(R.id.toggle_enable);
        LifecycleTimelineView lifecycleTimelineView = rootView.findViewById(R.id.lifecycleTimelineView);
        LifecycleView lifecycleView = rootView.findViewById(R.id.timeDomainPlotView);
        lifecycleView.setLinePoints(LifecycleRecorder.getInstance().getLifecycleTraces());
        //toggle_enable.setChecked(LifecycleManager.getInstance().isEnable());
        //toggle_enable.setOnToggleChanged((view, on) -> LifecycleManager.getInstance().setEnable(on));

        RadioGroup rg_transitionType = rootView.findViewById(R.id.rg_transitionType);
        rg_transitionType.setOnCheckedChangeListener((group, checkedId) -> {
            if (checkedId == R.id.rb_transitionType_01) {
                lifecycleTimelineView.setTransitionType(LifecycleTimelineView.TransitionType.horizontal);
                lifecycleView.setTransitionType(LifecycleView.TransitionType.horizontal);
            } else if (checkedId == R.id.rb_transitionType_02) {
                lifecycleTimelineView.setTransitionType(LifecycleTimelineView.TransitionType.vertical);
                lifecycleView.setTransitionType(LifecycleView.TransitionType.vertical);
            } else if (checkedId == R.id.rb_transitionType_03) {
                lifecycleTimelineView.setTransitionType(LifecycleTimelineView.TransitionType.transitionXY);
                lifecycleView.setTransitionType(LifecycleView.TransitionType.transitionXY);
            } else if (checkedId == R.id.rb_transitionType_04) {
                lifecycleTimelineView.setTransitionType(LifecycleTimelineView.TransitionType.none);
                lifecycleView.setTransitionType(LifecycleView.TransitionType.none);
            }
        });
        RadioGroup rg_scaleType = rootView.findViewById(R.id.rg_scaleType);
        rg_scaleType.setOnCheckedChangeListener((group, checkedId) -> {
            if (checkedId == R.id.rg_scaleType_01) {
                lifecycleView.setScaleType(LifecycleView.ScaleType.scaleX);
                lifecycleView.setScaleType(LifecycleView.ScaleType.scaleX);
            } else if (checkedId == R.id.rg_scaleType_02) {
                lifecycleView.setScaleType(LifecycleView.ScaleType.scaleY);
                lifecycleView.setScaleType(LifecycleView.ScaleType.scaleY);
            } else if (checkedId == R.id.rg_scaleType_03) {
                lifecycleView.setScaleType(LifecycleView.ScaleType.scaleXY);
                lifecycleView.setScaleType(LifecycleView.ScaleType.scaleXY);
            } else if (checkedId == R.id.rg_scaleType_04) {
                lifecycleView.setScaleType(LifecycleView.ScaleType.none);
                lifecycleView.setScaleType(LifecycleView.ScaleType.none);
            }
        });
        lifecycleTimelineView.addTrace(LifecycleRecorder.getInstance().getLifecycleTraces());
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}